<?php
class ResourceComposer extends Resource
{
	private $ComposerID;
	private $Surname;
	private $FirstName;
	private $SecondNames;
	private $DOB;
	private $DOD;
	private $Biography;
	
	
	public function __construct($database, $resourceID)
	{
		$this->database = $database;
		parent::__construct($database, $resourceID);
		
		if ($resourceID != 0)
		{
			$sql = "SELECT * from Composers WHERE ResourceIDP=".$this->resourceID;
//			echo $sql;
			$this->database->ExecuteSQL($sql);
			$row = $this->database->getRow();
			
			$this->ComposerID = $row['ComposerID'];
			$this->Surname = $row['Surname'];
			$this->FirstName = $row['FirstName'];
			$this->SecondNames = $row['SecondNames'];
			$this->DOB = new DateTime($row['DOB']);
			$this->DOD = new DateTime($row['DOD']);
			$this->Biography = $row['Biography'];

		}
		
		
	}
	
	public function loadComposer($composerID)
	{
		if ($composerID != 0)
		{
			$sql = "SELECT * from Composers WHERE ComposerID=".$composerID;
//			echo $sql;
			$this->database->ExecuteSQL($sql);
			$row = $this->database->getRow();
			
			$this->ComposerID = $row['ComposerID'];
			$this->Surname = $row['Surname'];
			$this->FirstName = $row['FirstName'];
			$this->SecondNames = $row['SecondNames'];
			$this->DOB = new DateTime($row['DOB']);
			$this->DOD = new DateTime($row['DOD']);
			$this->Biography = $row['Biography'];
			
			// load parent resource info

			$sql = "SELECT * FROM Resources WHERE ResourceID=".$row['ResourceIDP'];
			$this->database->ExecuteSQL($sql);
			$row = $this->database->getRow();
			$this->title = $row['ResourceTitle'];
			$this->description = $row['ResourceDescription'];
			$this->keywords = $row['ResourceKeywords'];
		}
		
	}
	
	public function getFullHTML()
	{
		$DOB=(isset($this->DOB))?$this->DOB->format('Y'):"?";
		$DOD=(isset($this->DOD))?$this->DOD->format('Y'):"?";
		if($DOB=='0001')$DOB='?';
		if($DOD=='0001')$DOD='?';
		
		$html = "<span class=\"ListMainTitle\">Composer: ".$this->title."</span>\n";
		$html .= "<p class=\"floatstop\" />\n";
		$html .= "<span class=\"ListTitle\">Name:</span><span class=\"ListDescription\">".$this->FirstName." ".$this->SecondNames." ".$this->Surname."</span>\n";
		$html .= "<p class=\"floatstop\" />\n";
		
		$html .= "<span class=\"ListTitle\">Dates:</span><span class=\"ListDescription\">".$DOB." - ".$DOD."</span>\n";
		$html .= "<p class=\"floatstop\" />\n";
		
		$html .= "<span class=\"ListTitle\">Biography:</span><span class=\"ListDescription\">".$this->Biography."</span>\n";
		$html .= "<p class=\"floatstop\" />\n";
				
		return $html;
	}
	
	
		public function getSummaryHTML()
	{
		$DOB=(isset($this->DOB))?$this->DOB->format('Y'):"?";
		$DOD=(isset($this->DOD))?$this->DOD->format('Y'):"?";
		if($DOB=='0001')$DOB='?';
		if($DOD=='0001')$DOD='?';
		$html = "<p>".$this->FirstName." ".$this->SecondNames." ".$this->Surname."  ".$DOB." - ".$DOD."</p>\n";
		return $html;
	}
}

?>